package com.example.wan1.base.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.example.wan1.widget.LoadingView;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/***
 * @Author: zxd
 * @CreateDate: 2020/6/22 10:02
 * @Description:
 */
public abstract class BaseActivity extends AppCompatActivity {

    private Context mContext;
    protected Unbinder mUnbinder;


    protected abstract @LayoutRes
    int initLayoutId();

    protected abstract void initData();

    protected abstract void initView();

    protected LoadingView mLoadingView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(initLayoutId());
        mContext = this;
        mUnbinder = ButterKnife.bind(this);

        initData();
        initView();

        mLoadingView = new LoadingView(this);
    }

    @Override
    protected void onDestroy() {
        mUnbinder.unbind();
        super.onDestroy();
    }

    public void showLoading() {
        showLoading("");
    }

    public void showLoading(String msg) {
        if (mLoadingView != null) {
            mLoadingView.setVisibility(View.VISIBLE);
            mLoadingView.startFallAnimator();
        }
    }

    public void hideLoading() {
        if (mLoadingView != null)
            mLoadingView.setVisibility(View.INVISIBLE);
    }
}
